|
Radar Host Communication library
2020.08.13
|
This file defines the API to access a serial communication port. More...
#include <stddef.h>#include <stdint.h>Go to the source code of this file.
Macros | |
| #define | IFX_RADAR_VID "058B" |
| #define | IFX_RADAR_PID "0058" |
| #define | IFX_RADAR_FF_PID "0250" |
Typedefs | |
| typedef struct com_s | com_t |
Functions | |
| uint32_t | com_get_port_list (char *port_list, size_t buffer_size) |
| This function returns a list of available COM ports. More... | |
| com_t * | com_open (const char *port_name) |
| This functions opens the specified COM port. More... | |
| void | com_close (com_t *com_port) |
| This function closes the specified COM port. More... | |
| size_t | com_send_data (com_t *com_port, const void *data, size_t num_bytes) |
| This function sends data through an open COM port. More... | |
| size_t | com_get_data (com_t *com_port, void *data, size_t num_requested_bytes) |
| This function reads data from an open COM port. More... | |
| void | com_set_timeout (com_t *com_port, uint32_t timeout_period_ms) |
| This function changes the timeout period of an open COM port. More... | |
This file defines the API to access a serial communication port.
This interface is an abstraction of a serial communication port. The interface provides basic operations open, close, read and write. Additionally it allows to get a list of available ports.
Even though the name is 'COMPort', the actual communication may use a different type of connection (COM, USB, SPI, etc.). The implementation is platform specific and will look differently for each combination of platform and connection type.
Definition in file COMPort.h.
| void com_close | ( | com_t * | com_port | ) |
This function closes the specified COM port.
The function expects a handle to an open COM port that have been returned by com_open.
| [in] | com_port | The COM port that should be closed. |
| size_t com_get_data | ( | com_t * | com_port, |
| void * | data, | ||
| size_t | num_requested_bytes | ||
| ) |
This function reads data from an open COM port.
The function tries to read the specified number of bytes from an open COM port and stores them in the provided buffer. The function waits for the data, but returns after an internally defined timeout period and returns the number of received bytes.
The function expects a handle to an open COM port that have been returned by com_open.
| [in] | com_port | The open COM port. |
| [out] | data | A pointer to the buffer where the received data will be stored. |
| [in] | num_requested_bytes | The number of bytes that should be read from the COM port. |
| uint32_t com_get_port_list | ( | char * | port_list, |
| size_t | buffer_size | ||
| ) |
This function returns a list of available COM ports.
The port list is compiled into a zero terminated string, where all available ports are separated by a semicolon (';'). The string buffer to hold the port list must be provided by the caller. If the buffer is not sufficient to hold the names of all available ports, it is filled with as much complete port names as possible. Port names will not be truncated.
The function will return the number of available COM ports regardless of the number of port names that have been written to the buffer. The caller can count the number of names in the string buffer and compare with the returned number to check if it is sensible to call this function again with a bigger string buffer.
| [out] | port_list | A pointer to the string buffer where the port names will be written to. |
| [in] | buffer_size | The size of the string buffer in bytes. |
| com_t* com_open | ( | const char * | port_name | ) |
This functions opens the specified COM port.
The name of the COM port must be provided as zero terminated string. It is recommended to call com_get_port_list to find the available COM ports and pass one of the returned port names to the open function.
| [in] | port_name | A zero terminated string containing the name of the COM port |
| size_t com_send_data | ( | com_t * | com_port, |
| const void * | data, | ||
| size_t | num_bytes | ||
| ) |
This function sends data through an open COM port.
The function transmits each byte from the provided buffer through the specified COM port and returns after the last byte has been sent.
The function expects a handle to an open COM port that have been returned by com_open.
| [in] | com_port | The open COM port. |
| [in] | data | A pointer to the buffer containing the data to be sent. |
| [in] | num_bytes | The number of bytes in pBuffer. |
| void com_set_timeout | ( | com_t * | com_port, |
| uint32_t | timeout_period_ms | ||
| ) |
This function changes the timeout period of an open COM port.
This function changes the timeout period that will be used when data is read through com_get_data. That function will wait until timeout period is elapsed before returning, if not enough data is received.
The function expects a handle to an open COM port that have been returned by com_open.
| [in] | com_port | The open COM port. |
| [in] | timeout_period_ms | The new timeout period in milli seconds. |